package acm.蓝桥21;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class H区间修改_偷分 {
	static PriorityQueue<Integer>[] q = new PriorityQueue[26];
	static int maxn = (int) (1e5 + 10);
	static char[] src;
	static int n,m;

	public static void main(String[] args) {
		Reader sc = new Reader();
		for (int i = 0; i < 26; i++) {
			q[i] = new PriorityQueue<Integer>();
		}

		src = sc.nextLine().toCharArray();
		m=sc.nextInt();
		n=src.length;
		while(m-->0) {
			int l=sc.nextInt()-1;
			int r=sc.nextInt();
			char s=sc.nextChar(); 
			char e=sc.nextChar();
			while(l<r) {
				if(src[l]==s) {
					src[l]=e;
				}
				l++;
			}
		}
		sc.pr.println(new String(src));
		sc.pr.flush();
	}

	static class Reader {
		private PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		private StringTokenizer tokenizer = new StringTokenizer("");

		private String innerNextLine() {
			try {
				return reader.readLine();
			} catch (IOException ex) {
				return null;
			}
		}

		public boolean hasNext() {
			while (!tokenizer.hasMoreTokens()) { // 内存中没有
				String nextLine = innerNextLine();
				if (nextLine == null) { // 且没有下一行
					return false;
				}
				tokenizer = new StringTokenizer(nextLine); // 读入一行
			}
			return true;
		}

		public String nextLine() {
			tokenizer = new StringTokenizer(""); // 清空内存中的字符
			return innerNextLine();
		}

		public void clear() {
			tokenizer = new StringTokenizer("");
		}

		public String next() {
			hasNext();
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		// public BigInteger nextBigInt() {
//	        return new BigInteger(next());
//	    }

	}
}
